package entity

import (
	"strconv"
	"time"

	"shqsoft.cn/pasnj/base"
	"shqsoft.cn/pasnj/bi/cube"
)

type CM_INDV_CUST_DIM struct {
	ID    int        `gorm:"column:JLID;AUTO_INCREMENT;primary_key;"`
	KHMC  string     `gorm:"column:客户姓名"`
	ZJLX  string     `gorm:"column:证件类型;"`
	ZHHM  string     `gorm:"column:证件号码;"`
	SEX   string     `gorm:"column:性别;"`
	CSRQ  *time.Time `gorm:"column:出生日期;type:date;"`
	SSJG  string     `gorm:"column:所属机构;"`
	DKSX  string     `gorm:"column:贷款授信额度;"`
	XYKSX string     `gorm:"column:信用卡授信额度;"`
	DFGZ  string     `gorm:"column:是否代发工资客户;"`
	GD    string     `gorm:"column:是否个贷客户;"`
	SJYH  string     `gorm:"column:是否手机银行客户;"`
	XYK   string     `gorm:"column:是否信用卡客户;"`
	CUID  int        `gorm:"column:cuid"`
	YG1   string     `gorm:"-"`
	ZB1   *float64   `gorm:"-"`
	YG2   string     `gorm:"-"`
	ZB2   *float64   `gorm:"-"`
	YG3   string     `gorm:"-"`
	ZB3   *float64   `gorm:"-"`
	YG4   string     `gorm:"-"`
	ZB4   *float64   `gorm:"-"`
	YG5   string     `gorm:"-"`
	ZB5   *float64   `gorm:"-"`
}

// TableName 零售客户信息
func (CM_INDV_CUST_DIM) TableName() string {
	return "V_CM_INDV_CUST_DIM"

}

func (c *CM_INDV_CUST_DIM) AfterFind() (err error) {
	var share *cube.Share
	share, err = cube.GetShare("indi_clie_divi")
	if err != nil {
		return
	}
	var diviMap map[string]float64
	diviMap, err = share.GetDivision(strconv.Itoa(c.CUID))
	if err != nil {
		return
	}
	i := 0
	for k, v := range diviMap {
		val := v
		i++
		switch i {
		case 1:
			c.YG1 = k
			c.ZB1 = &val
		case 2:
			c.YG2 = k
			c.ZB2 = &val
		case 3:
			c.YG3 = k
			c.ZB3 = &val
		case 4:
			c.YG4 = k
			c.ZB4 = &val
		case 5:
			c.YG5 = k
			c.ZB5 = &val
		default:
			break
		}
	}
	return
}

// CM_INDV_CUST_DIM 零售客户信息
func CM_INDV_CUST_DIMEF() base.EntityFunc {
	return func() interface{} {
		entity := CM_INDV_CUST_DIM{}
		return &entity
	}
}

// CM_INDV_CUST_DIM 零售客户信息
func CM_INDV_CUST_DIMESF() base.EntitiesFunc {
	return func() interface{} {
		var entities []CM_INDV_CUST_DIM
		return &entities
	}
}
func init() {
	dao := base.NewDefaultDao(CM_INDV_CUST_DIMEF(), CM_INDV_CUST_DIMESF(), nil)
	filter := base.DefaultFilter{
		FilterColName: "CUID",
		TableName:     "T_INDI_CLIE_YGFC",
		EmidColName:   "emid",
		AcidColName:   "CUID",
		WhereCause:    " DTID=dbo.GetDateToInt(dbo.GetCurSysDate())",
	}
	dao.Fileter = &filter
	base.DaoPoolObj.Put("CM_INDV_CUST_DIM", dao)
}
